//
//  LoginViewController.m
//  FineNurse
//
//  Created by 陈日红 on 2018/5/5.
//  Copyright © 2018年 TT_UED. All rights reserved.
//

#import "LoginViewController.h"
#import <Masonry.h>

@interface LoginViewController ()

@property (nonatomic, strong) UIScrollView *scrollView;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;
    
    UIImage *image = [UIImage imageNamed:@"LoginBGP"];
    self.view.layer.contents = (id)image.CGImage;
    self.view.layer.backgroundColor = [UIColor clearColor].CGColor;
    
    //self.scrollView = [[UIScrollView alloc]init];
   // self.scrollView.backgroundColor = [UIColor orangeColor];
   // [self.view addSubview:self.scrollView];
    
    
//    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.right.bottom.equalTo(self.view);
//    }];
//
    [self setUi];
}

-(void) setUi{
    
    UILabel *name = [[UILabel alloc]init];
    [name setText:@"工号："];
    [name setTextAlignment:NSTextAlignmentRight];
    
    UITextField *nameTxt = [[UITextField alloc]init];
    nameTxt.borderStyle = UITextBorderStyleRoundedRect;
    nameTxt.placeholder = @"您的工号";
    nameTxt.returnKeyType = UIReturnKeyNext;
    
    UILabel *pwd = [[UILabel alloc]init];
    [pwd setText:@"密码："];
    [pwd setTextAlignment:NSTextAlignmentRight];
    
    UITextField *pwdTxt = [[UITextField alloc]init];
    pwdTxt.borderStyle = UITextBorderStyleRoundedRect;
    pwdTxt.placeholder = @"您的密码";
    pwdTxt.secureTextEntry = YES;
    pwdTxt.returnKeyType = UIReturnKeyDone;
    
    UIButton *loginBtn = [[UIButton alloc]init];
    [loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    [loginBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [loginBtn setBackgroundColor:UIColor.blueColor];
    loginBtn.layer.cornerRadius = 5;
    
    UIButton *cancelBtn = [[UIButton alloc]init];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:UIColor.darkGrayColor forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(doCancel:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(doCancel:)];
    [self.navigationItem setRightBarButtonItem:right];
    
    UIView *v1 = [[UIView alloc]init];
    [v1 addSubview:name];
    [v1 addSubview:nameTxt];
    [v1 addSubview:pwd];
    [v1 addSubview:pwdTxt];
    [v1 addSubview:loginBtn];
    [v1 addSubview:cancelBtn];
    
    [self.view addSubview:v1];
    //self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, 300);
   
    [v1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.width.height.equalTo(self.view);
    }];

    UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(padding.left*3);
        make.centerY.equalTo(self.view.mas_centerY).offset(-200);
        make.width.mas_equalTo(@100);
        make.height.mas_equalTo(@50);
    }];
    
    [nameTxt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(name.mas_right).offset(padding.left);
        make.right.equalTo(self.view.mas_right).offset(-padding.right*3);
        make.centerY.equalTo(name.mas_centerY);
        make.height.mas_equalTo(@40);
    }];

    [pwd mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.height.equalTo(name);
        make.top.equalTo(name.mas_bottom).offset(padding.top);
    }];
    
    [pwdTxt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.height.equalTo(nameTxt);
        make.centerY.equalTo(pwd.mas_centerY);
    }];
    
    [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(pwdTxt.mas_bottom).offset(padding.top*3);
        make.right.equalTo(pwdTxt.mas_right);
        make.left.equalTo(pwd.mas_left);
        make.height.mas_equalTo(@40);
    }];
    
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(loginBtn.mas_top);
//        make.height.width.equalTo(loginBtn);
//        make.right.equalTo(loginBtn.mas_left).offset(-padding.right);
        
        make.top.equalTo(loginBtn.mas_bottom).offset(padding.top);
        make.right.equalTo(loginBtn.mas_right);
        make.width.mas_equalTo(@80);
        make.height.mas_equalTo(@40);
    }];
    
    
   // [nameTxt becomeFirstResponder];
}

-(void)doCancel:(UIButton *)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(void)doLogin:(UIButton *)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
